<?php
namespace app\web\home;


use app\web\model\Blacklist as myModel;

/**
 * 黑名单相关
 */
class Blacklist extends Base 
{
    public function getList()
    {
        $id = $this->getCurrentId();
        if($this->appkey == 1){
            $where['technician_id'] = $id;
        }else{
            $where['shop_id'] = $id;
        }
        $list = myModel::where($where)->field('id,blackout,mobile')->order('id desc')->paginate();
        return show(200,'拉黑列表',$list);
    }

    public function create()
    {
        if($this->auth_status == 2) return show(400,'无操作权限');
        $post = input('post.');
        $this->validate($post,'Blacklist');
        $id = $this->getCurrentId();
        if($this->appkey == 1){
            $post['technician_id'] = $id;
            if(myModel::where(['mobile'=>$post['mobile'],'technician_id'=>$id])->find()){
                return show(400,'该手机号已被拉黑,不可重复拉黑');
            }
        }else{
            $post['shop_id'] = $id;
            if(myModel::where(['mobile'=>$post['mobile'],'shop_id'=>$id])->find()){
                return show(400,'该手机号已被拉黑,不可重复拉黑');
            }
        }

        $res = myModel::create($post);
        if($res->isEmpty()) return show(400,'拉黑失败');
        return show(200,'拉黑成功');
    }

    public function del($id){
        if($this->auth_status == 2) return show(400,'无操作权限');
        myModel::destroy($id);
        return show(200,'删除成功');
    }
}